Use the replication option in TypeOrmModule.forRoot() to define master and slave connection details. TypeORM automatically routes write operations (INSERT, UPDATE, DELETE) to the master and read operations (SELECT) to slaves in round-robin. Force master reads by creating a QueryRunner with the 'master' option for read-your-writes consistency after mutations.
TypeORM automatically routes writes to master and reads to slaves — no code changes needed.
Slaves are selected in round-robin order — traffic is distributed evenly across replicas.
Force master reads immediately after a write to avoid replication lag causing stale reads.
createQueryRunner('master') bypasses the replica routing for a specific query.
Monitor replication lag — a slow replica serving stale data on reads can cause subtle bugs.